<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="80px">
      <el-form-item prop="storeId">
        <!-- <treeselect v-model="queryParams.storeId" :options="storeOptions" :show-count="true" placeholder="请选择仓库"
          style="width: 480px" size="mini"/> -->
        <el-select v-model="queryParams.storeId" placeholder="仓库" clearable size="small">
          <el-option v-for="dict in storeOptions" :key="dict.id" :label="dict.label" :value="dict.id" />
        </el-select>
      </el-form-item>
      <el-form-item prop="areaId" v-if="queryParams.storeId">
        <el-select v-model="queryParams.areaId" placeholder="请选择库区" clearable size="small">
          <el-option v-for="item in storeAreaOptions" :key="item.id" :label="item.name" :value="item.id" />
        </el-select>
      </el-form-item>

      <el-form-item prop="inventoryNo">
        <el-input v-model="queryParams.inventoryNo" placeholder="单号" clearable size="small"
          @keyup.enter.native="handleQuery" />
      </el-form-item>

      <el-form-item prop="inventoryUser">
        <el-select v-model="queryParams.inventoryUser" placeholder="盘点人" clearable size="small">
          <el-option v-for="item in userOptions" :key="item.userId" :label="item.nickName" :value="item.userName" />
        </el-select>
      </el-form-item>

      <el-form-item prop="operateTime">
        <el-date-picker clearable size="small" v-model="queryParams.operateTime" type="date" value-format="yyyy-MM-dd"
          placeholder="盘点时间" style="width: 130px">
        </el-date-picker>
      </el-form-item>

      <el-form-item>
        <el-date-picker v-model="daterangeCreateTime" size="small" style="width: 240px" value-format="yyyy-MM-dd"
          type="daterange" range-separator="-" start-placeholder="创建起始日期" end-placeholder="截止日期"></el-date-picker>
      </el-form-item>

      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
        <el-button type="warning" icon="el-icon-download" size="mini" @click="openSttatisticsExport">盘点计划导出</el-button>
        <el-button type="warning" icon="el-icon-download" size="mini" @click="openExport">盘点结果导出</el-button>
<!--        <el-button type="warning" icon="el-icon-download" size="mini" @click="openCheckExport">盘点结果抽检</el-button>-->
      </el-form-item>
    </el-form>

    <el-row>
      <el-col :span="6" class="mb10">
        <el-radio-group v-model="queryParams.sendStatus" @change="radioChange">
          <el-radio-button v-for="tab in tabs" :label="tab.label">
            <el-badge :value="tab.badge" class="item">
              {{tab.name}}
            </el-badge>
          </el-radio-button>
        </el-radio-group>
      </el-col>
      <el-col :span="18">
        <el-radio-group v-model="queryParams.region" @change="statisticsChange">
          <el-radio-button label="">全部</el-radio-button>
          <el-radio-button v-for="tab in dict.type.wms_put_task_area" :label="tab.value" v-if="tab.value != 'QB'">
            {{tab.label}}
          </el-radio-button>
        </el-radio-group>
      </el-col>
    </el-row>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleAdd"
          v-hasPermi="['wms:inventoryPlan:add']">新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="success" plain icon="el-icon-edit" size="mini" :disabled="single" @click="handleUpdate"
          v-hasPermi="['wms:inventoryPlan:edit']">修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="danger" plain icon="el-icon-delete" size="mini" :disabled="multiple" @click="handleDelete"
          v-hasPermi="['wms:inventoryPlan:remove']">删除</el-button>
      </el-col>
<!--      <el-col :span="1.5">-->
<!--        <el-button type="warning" plain icon="el-icon-download" size="mini" @click="handleExport"-->
<!--          v-hasPermi="['wms:inventoryPlan:export']">导出</el-button>-->
<!--      </el-col>-->
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="inventoryPlanList" @selection-change="handleSelectionChange" border stripe>
      <el-table-column type="selection" width="55" align="center" fixed="left" />
      <!-- <el-table-column label="盘点id" prop="id" v-if="true" /> -->
      <el-table-column label="盘点编号" min-width="120" prop="inventoryNo" width="130" fixed="left">
        <template slot-scope="scope">
          <el-link type="primary" @click="handleInfo(scope.row)">{{scope.row.inventoryNo}}</el-link>
        </template>
      </el-table-column>
      <el-table-column label="仓库" min-width="300" prop="storeName" fixed="left">
        <template slot-scope="scope">
          {{scope.row.storeName}}
          {{scope.row.areaName?"/"+scope.row.areaName:""}}
          {{scope.row.groupName?"/"+scope.row.groupName:""}}
          {{scope.row.cabinetName?"/"+scope.row.cabinetName:""}}
          {{scope.row.floors?"/"+scope.row.floors+"层":""}}
          {{scope.row.locatorName?"/"+scope.row.locatorName:""}}
        </template>
      </el-table-column>
      <el-table-column label="地区" width="100" prop="region" fixed="left">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.wms_put_task_area" :value="scope.row.region" />
        </template>
      </el-table-column>
      <!-- <el-table-column label="部门" prop="deptName" /> -->
      <el-table-column label="盘点人" prop="nickName" />
      <el-table-column label="监盘人" prop="watcher" />
      <el-table-column label="派单人" prop="dispatcher" />
      <el-table-column label="账面数量" prop="books" />
      <el-table-column label="盘点数量" prop="nums" />
      <el-table-column label="盘点结果" prop="results">
        <template slot-scope="scope">
          <span
            :style="scope.row.results > 0 ?'color:#67C23A':(scope.row.results < 0 ? 'color:#F56C6C':'')">{{scope.row.results}}</span>
        </template>
      </el-table-column>
      <el-table-column label="计划开始时间" prop="operateTime" min-width="160">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.planTime) }}</span>
        </template>
      </el-table-column>
      <el-table-column label="盘点时间" prop="operateTime" min-width="160">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.operateTime) }}</span>
        </template>
      </el-table-column>
      <el-table-column label="状态" prop="status" width="80" fixed="right">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.wms_inventory_status" :value="scope.row.status" />
        </template>
      </el-table-column>
      <el-table-column label="操作" class-name="small-padding fixed-width" align="center" fixed="right">
        <template slot-scope="scope">
          <el-button size="mini" type="text" icon="el-icon-view" @click="handleInfo(scope.row)"
            v-hasPermi="['wms:inventoryPlan:query']">查看</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination v-show="total>0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
      @pagination="getList" />
    <!-- 添加或修改盘点计划对话框 -->
    <el-dialog :title="title" width="1080px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="110px">

        <el-row :gutter="15">
          <el-col :span="8">
            <el-form-item label="仓库" prop="storeId">
              <treeselect v-model="form.storeId" :options="storeOptions" :show-count="true" placeholder="请选择仓库" />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="部门" prop="deptId">
              <treeselect v-model="form.deptId" :options="deptOptions" :show-count="true" placeholder="管理部门"
                style="width: 100%" size="small" />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="盘点人" prop="inventoryUser">
              <el-select v-model="form.inventoryUser" placeholder="请选择盘点人" style="width: 100%">
                <el-option v-for="item in userOptions" :key="item.userId" :label="item.nickName"
                  :value="item.userName" />
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="15">
          <el-col :span="8">
            <el-form-item label="账面数量" prop="books">
              <el-input v-model="form.books" placeholder="请输入账面数量" />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="盘点数量" prop="nums">
              <el-input v-model="form.nums" placeholder="请输入盘点数量" />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="盘点结果" prop="results">
              <el-input v-model="form.results" placeholder="请输入盘点结果" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="15">
          <el-col :span="8">
            <el-form-item label="状态" prop="status">
              <el-select v-model="form.status" placeholder="请选择状态">
                <el-option v-for="dict in dict.type.wms_inventory_status" :key="dict.value" :label="dict.label"
                  :value="dict.value"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="15">
          <el-col :span="24">
            <el-form-item label="备注" prop="remark">
              <el-input v-model="form.remark" type="textarea" placeholder="请输入内容" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="24">
            <el-card shadow="hover">
              <div slot="header" class="clearfix">
                <span>盘点清单</span>
              </div>
              <el-table :data="form.items" border stripe>
                <el-table-column label="物品编号" prop="pno">
                  <template slot-scope="scope">
                    <el-input placeholder="请输入物品编号" v-model="scope.row.pno" />
                  </template>
                </el-table-column>
                <el-table-column label="物品名称" prop="name">
                  <template slot-scope="scope">
                    <el-input placeholder="请输入物品名称" v-model="scope.row.name" />
                  </template>
                </el-table-column>
                <el-table-column label="库区" prop="areaName">
                  <template slot-scope="scope">
                    <el-input placeholder="请输入物品库区" v-model="scope.row.areaName" />
                  </template>
                </el-table-column>
                <el-table-column label="库位" prop="locatorName">
                  <template slot-scope="scope">
                    <el-input placeholder="请输入物品库区" v-model="scope.row.locatorName" />
                  </template>
                </el-table-column>
                <el-table-column label="账面数量" prop="books">
                  <template slot-scope="scope">
                    <el-input v-model="scope.row.books" placeholder="请输入账面数量" />
                  </template>
                </el-table-column>
                <el-table-column label="盘点数量" prop="nums">
                  <template slot-scope="scope">
                    <el-input v-model="scope.row.nums" placeholder="请输入盘点数量" />
                  </template>
                </el-table-column>
                <el-table-column label="盘点结果" prop="results">
                  <template slot-scope="scope">
                    <el-input v-model="scope.row.results" placeholder="请输入盘点结果" />
                  </template>
                </el-table-column>
              </el-table>
              <pagination v-show="itemTotal>0" :total="itemTotal" :page.sync="formParams.pageNum"
                :limit.sync="formParams.pageSize" @pagination="loadInventory" />
            </el-card>
          </el-col>
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button :loading="buttonLoading" type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
    <el-drawer :title="title" :visible.sync="open" size="90%" :before-close="close">
      <div class="mb20 ml20">
        <span style="font-size: 20px;">{{form.inventoryNo}}</span>
      </div>
      <el-card>
        <el-tabs v-model="activeName" @tab-click="handleClick">
          <el-tab-pane label="盘点信息" name="1">
            <el-descriptions :column="2" border>
              <el-descriptions-item label="盘点仓库">
                {{form.storeName}}
              </el-descriptions-item>
              <el-descriptions-item label="盘点库区">
                {{form.areaName}}
              </el-descriptions-item>
              <el-descriptions-item label="盘点货柜">
                {{form.groupName}}
              </el-descriptions-item>
              <el-descriptions-item label="盘点货架">
                {{form.cabinetName}}
              </el-descriptions-item>
              <el-descriptions-item label="盘点层数">
                {{form.floors}}层
              </el-descriptions-item>
              <el-descriptions-item label="盘点人">
                {{form.nickName}}
              </el-descriptions-item>
              <el-descriptions-item label="监盘人">
                {{form.watcher}}
              </el-descriptions-item>
              <el-descriptions-item label="派单人">
                {{form.dispatcher}}
              </el-descriptions-item>
              <el-descriptions-item label="计划开始时间">
                {{form.planTime}}
              </el-descriptions-item>
              <el-descriptions-item label="盘点状态">
                <dict-tag :options="dict.type.wms_inventory_status" :value="form.status" />
              </el-descriptions-item>
              <el-descriptions-item label="备注" :span="2">
                {{form.remark}}
              </el-descriptions-item>
            </el-descriptions>

            <el-descriptions :column="3" border class="mt10">
              <el-descriptions-item label="账面数量">
                {{form.books}}
              </el-descriptions-item>
              <el-descriptions-item label="盘点数量">
                {{form.nums}}
              </el-descriptions-item>
              <el-descriptions-item label="盘点结果">
                <el-tag :type="form.results > 0 ?'success':(form.results < 0?'danger':'')">{{form.results}}</el-tag>
              </el-descriptions-item>
            </el-descriptions>

            <el-button type="warning" plain icon="el-icon-download" size="mini" @click="exportPlanPro"
                       v-hasPermi="['wms:inventoryPlan:export']" style="margin-top: 1%">导出列表数据</el-button>
            <el-button type="danger" plain icon="el-icon-delete" size="mini" @click="deletePlanPro"
                       v-hasPermi="['wms:inventoryPlan:export']" style="margin-top: 1%">删除</el-button>

            <u-table :data="form.items" border stripe use-virtual
                     :row-height="40"
                     :height="320" class="mt10" @selection-change="handleSelectionChangePro">
              <u-table-column type="selection" width="55" :reserve-selection="true" />
              <u-table-column type="index" width="55" align="center" />
              <u-table-column label="物品编号" align="center" prop="pno"></u-table-column>
              <u-table-column label="物品名称" align="center" prop="name"></u-table-column>
              <u-table-column label="库区" align="center" prop="areaName"></u-table-column>
              <u-table-column label="库位" align="center" prop="locatorName"> </u-table-column>
              <u-table-column label="账面数量" align="center" prop="books"></u-table-column>
              <u-table-column label="盘点数量" align="center" prop="nums"></u-table-column>
              <u-table-column label="盘点结果" align="center" prop="results">
                <template slot-scope="scope">
                  <el-tag
                    :type="scope.row.results > 0 ?'success':(scope.row.results < 0?'danger':'')">{{scope.row.results}}</el-tag>
                </template>
              </u-table-column>
            </u-table>
<!--            <el-table :data="form.items" border stripe max-height="320" class="mt10" @selection-change="handleSelectionChangePro">-->
<!--              <el-table-column type="selection" width="55" :reserve-selection="true" />-->
<!--              <el-table-column type="index" width="55" align="center" />-->
<!--              <el-table-column label="物品编号" align="center" prop="pno"></el-table-column>-->
<!--              <el-table-column label="物品名称" align="center" prop="name"></el-table-column>-->
<!--              <el-table-column label="库区" align="center" prop="areaName"></el-table-column>-->
<!--              <el-table-column label="库位" align="center" prop="locatorName"> </el-table-column>-->
<!--              <el-table-column label="账面数量" align="center" prop="books"></el-table-column>-->
<!--              <el-table-column label="盘点数量" align="center" prop="nums"></el-table-column>-->
<!--              <el-table-column label="盘点结果" align="center" prop="results">-->
<!--                <template slot-scope="scope">-->
<!--                  <el-tag-->
<!--                    :type="scope.row.results > 0 ?'success':(scope.row.results < 0?'danger':'')">{{scope.row.results}}</el-tag>-->
<!--                </template>-->
<!--              </el-table-column>-->
<!--            </el-table>-->
          </el-tab-pane>
          <el-tab-pane label="盘点结果" name="2">
            <el-card class="mb10 mt10">
              <el-card class="box-card" style="background-color:#fff;" shadow="never">
                <div>
                  <el-button type="warning" icon="el-icon-printer" size="mini" class="fr ml10"
                    @click="handlePrint(form.inventoryNo+'盘点结果')">下载打印</el-button>
                </div>
              </el-card>
              <div ref="printOrderPre" id="printOrderPre" style="background-color:#fff;">
                <el-card id="handoverCard" class="box-card" style="padding: 50px 2vw 30px 2vw;background-color:#fff;"
                  shadow="never">
                  <template v-for="(listitem,ind) in listItems">

                    <div v-if="ind == 0" ref="headerDiv" slot="header"
                      style="text-align: center;font-size:26px;margin-bottom: 20px;font-weight: 800;padding-bottom: 15px;">
                      <el-divider content-position="right">{{form.inventoryNo}}</el-divider>
                      <span>盘点结果</span>
                    </div>
                    <el-descriptions v-if="ind == 0" ref="headerDesc" :column="3" class="mb10 mt10"
                      :labelStyle="{'backgroundColor':'#fff','fontSize':'16px','fontWeight':'bold'}"
                      :contentStyle="{'fontSize':'16px','fontWeight':'bold'}">
                      <el-descriptions-item label="盘点编号">{{form.inventoryNo}}</el-descriptions-item>
                      <el-descriptions-item label="计划时间">{{parseTime(form.planTime)}}</el-descriptions-item>
                      <el-descriptions-item label="盘点时间">{{parseTime(form.operateTime)}}</el-descriptions-item>
                      <el-descriptions-item label="盘点仓库">{{form.storeName}}</el-descriptions-item>
                      <el-descriptions-item label="库区库位" :span="2">
                        {{form.areaName?form.areaName+(form.groupName?'/'+form.groupName+(form.cabinetName?'/'+form.cabinetName+(form.floors?'/'+form.floors:'/全部'):'/全部'):'/全部'):'全部'}}
                      </el-descriptions-item>
                      <el-descriptions-item label="盘点人">{{form.nickName}}</el-descriptions-item>
                      <el-descriptions-item label="监盘人">{{form.watcher}}</el-descriptions-item>
                      <el-descriptions-item label="派单人">{{form.dispatcher}}</el-descriptions-item>
                      <el-descriptions-item label="账面数量">{{form.books}}</el-descriptions-item>
                      <el-descriptions-item label="盘点数量">{{form.nums}}</el-descriptions-item>
                      <el-descriptions-item label="盘点结果">{{form.results}}</el-descriptions-item>
                    </el-descriptions>
                    <div style="width: 100%;height: 100px;" v-if="ind > 0 && listitem.length > 0">
                      <el-divider content-position="right">{{form.inventoryNo}}</el-divider>
                    </div>
                    <el-table :data="listitem" v-if="ind == 0" border
                      :headerCellStyle="{'backgroundColor':'#fff','fontSize':'16px','fontWeight':'bold'}"
                      :cell-style="{'fontSize':'16px','fontWeight':'bold','border-bottom':'1px soild #000'}"
                      style="margin-bottom: 250px;">
                      <el-table-column label="序号" width="60" align="center">
                        <template slot-scope="scope">
                          {{scope.$index+1 + ind*25}}
                        </template>
                      </el-table-column>
                      <el-table-column label="财物编号" prop="pno" width="160" />
                      <el-table-column label="物品名称" prop="name" />
                      <el-table-column label="仓库" prop="storeName" width="80" />
                      <el-table-column label="库区" prop="areaName" />
                      <el-table-column label="存放位置" prop="locatorName" />
                      <el-table-column label="物品编码" prop="qrcode" width="180" />
                      <el-table-column label="盘点方式" prop="planMode" align="center">
                        <template slot-scope="scope">
                          <dict-tag :options="dict.type.wms_inventory_plan_mode" :value="scope.row.planMode" />
                        </template>
                      </el-table-column>
                      <el-table-column label="账面数量" prop="books" align="center" />
                      <el-table-column label="盘点数量" prop="nums" align="center" />
                      <el-table-column label="盘点结果" prop="results" align="center" />
                    </el-table>
                    <el-table :data="listitem" v-if="ind > 0 && listitem.length > 0" border
                      :headerCellStyle="{'backgroundColor':'#fff','fontSize':'16px','fontWeight':'bold'}"
                      :cell-style="{'fontSize':'16px','fontWeight':'bold','border-bottom':'1px soild #000'}"
                      :style="ind == listItems.length - 1?'margin-top: 0px;':'margin-bottom: 220px;margin-top: 0px;'">
                      <el-table-column label="序号" width="60" align="center">
                        <template slot-scope="scope">
                          {{scope.$index+1 + ind*25}}
                        </template>
                      </el-table-column>
                      <el-table-column label="财物编号" prop="pno" width="160" />
                      <el-table-column label="物品名称" prop="name" />
                      <el-table-column label="仓库" prop="storeName" width="80" />
                      <el-table-column label="库区" prop="areaName" />
                      <el-table-column label="存放位置" prop="locatorName" />
                      <el-table-column label="物品编码" prop="qrcode" width="180" />
                      <el-table-column label="盘点方式" prop="planMode" align="center">
                        <template slot-scope="scope">
                          <dict-tag :options="dict.type.wms_inventory_plan_mode" :value="scope.row.planMode" />
                        </template>
                      </el-table-column>
                      <el-table-column label="账面数量" prop="books" align="center" />
                      <el-table-column label="盘点数量" prop="nums" align="center" />
                      <el-table-column label="盘点结果" prop="results" align="center" />
                    </el-table>
                  </template>

                  <el-row class="mt20">
                    <el-col span="8" style="padding: 10px 15px;">
                      <div class="mb5">
                        <span>盘点人</span>
                      </div>
                      <span>
                        <el-image style="width: 100%;height: 150px;"
                          :src="require('@/assets/images/default-img.png')" />
                        <span>签字时间：</span>
                      </span>
                    </el-col>
                    <el-col span="8" style="padding: 10px 15px;">
                      <div class="mb5">
                        <span>监盘人签字</span>
                      </div>
                      <span>
                        <el-image style="width: 100%;height: 150px;"
                          :src="require('@/assets/images/default-img.png')" />
                        <span>签字时间：</span>
                      </span>
                    </el-col>
                    <el-col span="8" style="padding: 10px 15px;">
                      <div class="mb5">
                        <span>派单人签字</span>
                      </div>
                      <el-image style="width: 100%;height: 150px;" :src="require('@/assets/images/default-img.png')" />
                      <span>签字时间：</span>
                    </el-col>
                  </el-row>
                </el-card>
              </div>
              <vue-easy-print ref="easyPrint">
                <div ref="printOrderPre" id="printOrderPre" style="background-color:#fff;">
                  <el-card id="handoverCard" class="box-card" style="padding: 50px 2vw 30px 2vw;background-color:#fff;"
                    shadow="never">
                    <div slot="header"
                      style="text-align: center;font-size:26px;margin-bottom: 20px;font-weight: 800;padding-bottom: 15px;">
                      <el-divider content-position="right">{{form.inventoryNo}}</el-divider>
                      <span>盘点结果</span>
                    </div>
                    <el-descriptions ref="headerDesc" :column="3" class="mb10 mt10"
                      :labelStyle="{'backgroundColor':'#fff','fontSize':'16px','fontWeight':'bold'}"
                      :contentStyle="{'fontSize':'16px','fontWeight':'bold'}">
                      <el-descriptions-item label="盘点编号">{{form.inventoryNo}}</el-descriptions-item>
                      <el-descriptions-item label="计划时间">{{parseTime(form.planTime)}}</el-descriptions-item>
                      <el-descriptions-item label="盘点时间">{{parseTime(form.operateTime)}}</el-descriptions-item>
                      <el-descriptions-item label="盘点仓库">{{form.storeName}}</el-descriptions-item>
                      <el-descriptions-item label="库区库位" :span="2">
                        {{form.areaName?form.areaName+(form.groupName?'/'+form.groupName+(form.cabinetName?'/'+form.cabinetName+(form.floors?'/'+form.floors:'/全部'):'/全部'):'/全部'):'全部'}}
                      </el-descriptions-item>
                      <el-descriptions-item label="盘点人">{{form.nickName}}</el-descriptions-item>
                      <el-descriptions-item label="监盘人">{{form.watcher}}</el-descriptions-item>
                      <el-descriptions-item label="派单人">{{form.dispatcher}}</el-descriptions-item>
                      <el-descriptions-item label="账面数量">{{form.books}}</el-descriptions-item>
                      <el-descriptions-item label="盘点数量">{{form.nums}}</el-descriptions-item>
                      <el-descriptions-item label="盘点结果">{{form.results}}</el-descriptions-item>
                    </el-descriptions>
                    <el-table :data="form.items" border
                      :headerCellStyle="{'backgroundColor':'#fff','fontSize':'16px','fontWeight':'bold'}"
                      :cell-style="{'fontSize':'16px','fontWeight':'bold','border-bottom':'1px soild #000'}">
                      <el-table-column label="序号" width="60" type="index" align="center" />
                      <el-table-column label="财物编号" prop="pno" align="center" width="180" />
                      <el-table-column label="物品名称" prop="name" min-width="180"/>
                      <el-table-column label="仓库"  align="center" prop="storeName" width="80" />
                      <el-table-column label="库区"  align="center" prop="areaName" min-width="120"/>
                      <el-table-column label="存放位置" align="center" prop="locatorName" min-width="120"/>
                      <el-table-column label="物品编码" prop="qrcode" align="center" min-width="200" />
                      <el-table-column label="盘点方式" prop="planMode" min-width="100" align="center">
                        <template slot-scope="scope">
                          <dict-tag :options="dict.type.wms_inventory_plan_mode" :value="scope.row.planMode" />
                        </template>
                      </el-table-column>
                      <el-table-column label="账面数量" prop="books" align="center" width="120"/>
                      <el-table-column label="盘点数量" prop="nums" align="center" width="120"/>
                      <el-table-column label="盘点结果" prop="results" align="center" width="120"/>
                    </el-table>
                    <el-row class="mt20">
                      <el-col span="8" style="padding: 10px 15px;">
                        <div class="mb5">
                          <span>盘点人</span>
                        </div>
                        <span>
                          <el-image style="width: 100%;height: 150px;"
                            :src="require('@/assets/images/default-img.png')" />
                          <span>签字时间：</span>
                        </span>
                      </el-col>
                      <el-col span="8" style="padding: 10px 15px;">
                        <div class="mb5">
                          <span>监盘人签字</span>
                        </div>
                        <span>
                          <el-image style="width: 100%;height: 150px;"
                            :src="require('@/assets/images/default-img.png')" />
                          <span>签字时间：</span>
                        </span>
                      </el-col>
                      <el-col span="8" style="padding: 10px 15px;">
                        <div class="mb5">
                          <span>派单人签字</span>
                        </div>
                        <el-image style="width: 100%;height: 150px;"
                          :src="require('@/assets/images/default-img.png')" />
                        <span>签字时间：</span>
                      </el-col>
                    </el-row>
                  </el-card>
                </div>
              </vue-easy-print>
            </el-card>
          </el-tab-pane>
        </el-tabs>
      </el-card>
    </el-drawer>
    <plan-export
      v-if="planExportShow"
      @close="close"
    ></plan-export>
    <result-check-export
      v-if="resultCheckExportShow"
      @close="close"
    />
    <plan-statistics-export
      v-if="planStatisticsExportShow"
      @close="close"
    ></plan-statistics-export>
  </div>
</template>

<script>
import {
  listInventoryPlan,
  getInventoryPlan,
  delInventoryPlan,
  addInventoryPlan,
  updateInventoryPlan, removeDtl
} from "@/api/wms/inventoryPlan";
  import {
    listStore,
    storeTreeselect
  } from "@/api/wms/store";
  import {
    treeselect
  } from "@/api/system/dept";
  import {
    listUser
  } from "@/api/system/user"
  import {
    listInventory,
    getStatisticsTask
  } from "@/api/wms/inventory";
  import {
    listStoreArea
  } from '@/api/wms/storeArea';
  import {
    listCabinetGroup
  } from "@/api/wms/cabinetGroup";
  import {
    listCabinet
  } from "@/api/wms/cabinet";
  import {
    listLocator
  } from "@/api/wms/locator";
  import Treeselect from "@riophae/vue-treeselect";
  import "@riophae/vue-treeselect/dist/vue-treeselect.css";
  import {
    htmlToPdf,
    htmlToPdfInfo
  } from "@/utils/pdf.js"
  import vueEasyPrint from "vue-easy-print";
  import PlanExport from "@/views/wms/inventoryPlan/planExport.vue";
  import ResultCheckExport from "@/views/wms/inventoryPlan/resultCheckExport.vue";
  import PlanStatisticsExport from "@/views/wms/inventoryPlan/planStatisticsExport.vue";
  export default {
    name: "InventoryPlan",
    dicts: ['wms_inventory_status', 'sys_del_flag', 'sys_check_status', 'wms_inventory_plan_mode', 'wms_put_task_area'],
    components: {
      PlanExport,
      Treeselect,
      vueEasyPrint,
      PlanStatisticsExport,
      ResultCheckExport
    },
    data() {
      return {
        resultCheckExportShow: false,
        planExportShow: false,
        planStatisticsExportShow: false,
        // 按钮loading
        buttonLoading: false,
        // 遮罩层
        loading: true,
        // 选中数组
        ids: [],
        // 非单个禁用
        single: true,
        // 非多个禁用
        multiple: true,
        // 显示搜索条件
        showSearch: true,
        // 总条数
        total: 0,
        // 盘点计划表格数据
        inventoryPlanList: [],
        storeOptions: [],
        storeTree: [],
        storeName: undefined,
        deptOptions: [],
        userOptions: [],
        userFormOptions: [],
        inventory: [],

        storeAreaOptions: [],
        cabinetGroupOptions: [],
        cabinetOptions: [],
        locatorOptions: [],

        defaultProps: {
          children: "children",
          label: "label"
        },
        activeName: '1',
        // 弹出层标题
        title: "",
        // 是否显示弹出层
        open: false,
        // 图片时间范围
        daterangeCreateTime: [],
        // 图片时间范围
        daterangeUpdateTime: [],
        deletePlanProList: [],
        // 查询参数
        queryParams: {
          pageNum: 1,
          pageSize: 10,
          inventoryNo: undefined,
          storeId: undefined,
          inventoryUser: undefined,
          operator: undefined,
          operateTime: undefined,
          checker: undefined,
          checkStatus: undefined,
          checkTime: undefined,
          status: undefined,
          deptId: undefined,
          createBy: undefined,
          createTime: undefined,
          updateBy: undefined,
          updateTime: undefined,
          delFlag: '0',
          region: undefined
        },
        itemTotal: 0,
        formParams: {
          pageNum: 1,
          pageSize: 10,
          storeId: undefined
        },
        // 表单参数
        form: {},
        // 表单校验
        rules: {
          inventoryNo: [{
            required: true,
            message: "单号不能为空",
            trigger: "blur"
          }],
          storeId: [{
            required: true,
            message: "仓库id不能为空",
            trigger: "blur"
          }],
          inventoryUser: [{
            required: true,
            message: "盘点人不能为空",
            trigger: "blur"
          }],
          deptId: [{
            required: true,
            message: "部门id不能为空",
            trigger: "blur"
          }],
        },

        floorsOptions: [{
            name: '1层',
            value: '1'
          },
          {
            name: '2层',
            value: '2'
          },
          {
            name: '3层',
            value: '3'
          },
          {
            name: '4层',
            value: '4'
          },
          {
            name: '5层',
            value: '5'
          },
          {
            name: '6层',
            value: '6'
          },
          {
            name: '7层',
            value: '7'
          },
          {
            name: '8层',
            value: '8'
          }

        ],
        ano: undefined,

        tabs: [{
            label: undefined,
            name: '全部',
            badge: undefined,
            value: undefined
          },
          {
            label: '0',
            name: '待盘点',
            badge: undefined,
            value: '0'
          },
          {
            label: '1',
            name: '盘点中',
            badge: undefined,
            value: '1'
          },
          {
            label: '2',
            name: '暂停中',
            badge: undefined,
            value: '2'
          },
          {
            label: '3',
            name: '已盘完',
            badge: undefined,
            value: '3'
          }
        ],
        listItems: [],
      };
    },
    watch: {
      'queryParams.storeId': {
        handler(newVal, oldVal) {
          this.getStoreArea(newVal);
        },
        deep: true,
        immediate: true
      },
      // 'queryParams.areaId':{
      //   handler(newVal){
      //     if(newVal){
      //       this.storeAreaOptions.forEach(item=>{
      //          if(item.id == newVal){
      //            let ano = item.ano;
      //            this.ano = ano;
      //            if(ano == 'ZX'||ano == 'DX'){
      //              this.queryParams.cabinetGroupId = undefined;
      //            }else{
      //              this.getCabinetGroup(newVal)
      //            }
      //          }
      //       })
      //     }
      //   },
      //   deep: true,
      //   immediate: true

      // },
      // 'queryParams.cabinetGroupId': {
      //   handler(newVal, oldVal) {
      //     this.getCabinet(newVal);
      //     if(this.ano == 'CL'){
      //       this.getLocator();
      //     }
      //   },
      //   deep: true,
      //   immediate: true
      // },
      // 'queryParams.cabinetId': {
      //   handler(newVal, oldVal) {
      //     this.getLocator(newVal);
      //   },
      //   deep: true,
      //   immediate: true
      // },
      // 'queryParams.floors': {
      //   handler(newVal, oldVal) {
      //     this.getLocator(newVal);
      //   },
      //   deep: true,
      //   immediate: true
      // },
    },
    created() {
      this.getList();
      this.getStoreTreeselect();
      this.getTreeselect();
      this.getUsers();
    },
    activated() {
      const time = this.$route.query.t;
      if (time != null && time != this.uniqueId) {
        this.uniqueId = time;
        this.queryParams.pageNum = Number(this.$route.query.pageNum);
        this.getList();
      }
    },
    methods: {
      openExport(){
        this.planExportShow = true
      },
      openCheckExport(){
        this.resultCheckExportShow = true
      },
      openSttatisticsExport(){
        this.planStatisticsExportShow = true
      },
      /** 查询盘点计划列表 */
      getList() {
        this.loading = true;
        this.queryParams.params = {};
        if (null != this.daterangeCreateTime && '' != this.daterangeCreateTime) {
          this.queryParams.params["beginCreateTime"] = this.daterangeCreateTime[0];
          this.queryParams.params["endCreateTime"] = this.daterangeCreateTime[1];
        }
        if (null != this.daterangeUpdateTime && '' != this.daterangeUpdateTime) {
          this.queryParams.params["beginUpdateTime"] = this.daterangeUpdateTime[0];
          this.queryParams.params["endUpdateTime"] = this.daterangeUpdateTime[1];
        }
        listInventoryPlan(this.queryParams).then(response => {
          this.inventoryPlanList = response.rows;
          this.total = response.total;
          this.loading = false;

          this.tabs.forEach((item) => {
            if (item.label == this.queryParams.sendStatus) {
              item.badge = this.total;
            } else {
              item.badge = undefined;
            }
          })
        });
      },
      radioChange(e) {
        this.tabs.forEach(item => {
          if (item.label == e) {
            this.queryParams.status = item.value;
          }
        })
        this.getList();
      },
      handleClick(e) {

      },
      statisticsChange(item) {
        this.queryParams.region = item;
        this.getList();
      },
      /** 查询分类下拉树结构 */
      getStoreTreeselect() {
        storeTreeselect().then(response => {
          this.storeOptions = response.data;
        });
      },
      /** 查询部门下拉树结构 */
      getTreeselect() {
        treeselect().then(response => {
          this.deptOptions = response.data;
        });
      },
      /** 查询库区*/
      getStoreArea(storeId) {
        listStoreArea({
          storeId: storeId
        }).then(response => {
          this.storeAreaOptions = response.rows;
        })
      },
      /** 查询智能柜信息 */
      getCabinetGroup(areaId) {
        listCabinetGroup({
          areaId: areaId
        }).then(response => {
          this.cabinetGroupOptions = response.rows;
        })
      },
      /** 查询智能柜信息 */
      getCabinet(cabinetGroupId) {
        listCabinet({
          groupId: cabinetGroupId
        }).then(response => {
          this.cabinetOptions = response.rows;
        })
      },
      getLocator(cabinetId) {
        let floors = undefined;
        if (this.ano == 'PT') {
          floors = this.queryParams.floors;
        }
        listLocator({
          cabinetGroupId: this.queryParams.cabinetGroupId,
          cabinetId: cabinetId,
          floors: floors
        }).then(response => {
          this.locatorOptions = response.rows;
        })
      },
      deptChange() {
        this.getList();
        this.getUsers();
      },
      getUsers() {
        listUser({
          'userType': 'sys_user',
          'deptId': this.queryParams.deptId
        }).then(response => {
          this.userOptions = response.rows
        })
      },
      getFormUsers() {
        listUser({
          'userType': 'sys_user',
          'deptId': this.form.deptId
        }).then(response => {
          this.userFormOptions = response.rows
        })
      },
      selectDeptId() {
        this.getFormUsers();
      },
      loadInventory() {
        this.loading = true;
        listInventory(this.formParams).then(response => {
          this.form.items = response.rows
          this.itemTotal = response.total;
          this.loading = false;
        })
      },
      // 筛选节点
      filterNode(value, data) {
        if (!value) return true;
        return data.label.indexOf(value) !== -1;
      },
      // 节点单击事件
      handleNodeClick(data) {
        this.queryParams.storeId = data.id;
        this.handleQuery();
      },
      normalizer(node) {
        if (node.children && !node.children.length) {
          delete node.children;
        }
        return {
          id: node.id,
          label: node.name,
          children: node.children
        };
      },
      // 取消按钮
      cancel() {
        this.open = false;
        this.reset();
      },
      //关闭
      close() {
        this.open = false;
        this.planExportShow = false
        this.planStatisticsExportShow = false
        this.resultCheckExportShow = false
      },
      // 表单重置
      reset() {
        this.form = {
          id: undefined,
          inventoryNo: undefined,
          storeId: undefined,
          inventoryUser: undefined,
          operator: undefined,
          operateTime: undefined,
          checker: undefined,
          checkStatus: "0",
          checkTime: undefined,
          checkMemo: undefined,
          status: '0',
          remark: undefined,
          deptId: undefined,
          books: undefined,
          nums: undefined,
          results: undefined,
          pics: undefined,
          createBy: undefined,
          createTime: undefined,
          updateBy: undefined,
          updateTime: undefined,
          delFlag: undefined,
          items: []
        };
        this.resetForm("form");
      },
      /** 搜索按钮操作 */
      handleQuery() {
        this.queryParams.pageNum = 1;
        this.getList();
      },
      /** 重置按钮操作 */
      resetQuery() {
        this.daterangeCreateTime = [];
        this.daterangeUpdateTime = [];
        this.resetForm("queryForm");
        this.handleQuery();
      },
      // 多选框选中数据
      handleSelectionChange(selection) {
        this.ids = selection.map(item => item.id)
        this.single = selection.length !== 1
        this.multiple = !selection.length
      },
      handleSelectionChangePro(selection) {
        this.deletePlanProList = selection.map(item => item.pno);
      },
      /** 新增按钮操作 */
      handleAdd() {
        // this.reset();
        // this.open = true;
        // this.title = "添加盘点计划";
        // this.form.storeId = this.queryParams.storeId
        // this.form.deptId = this.queryParams.deptId
        this.$router.push({
          path: '/wms/inventoryPlan/add',
          query: {
            pageNum: this.queryParams.pageNum,
            storeId: this.queryParams.storeId,
            deptId: this.queryParams.deptId
          }
        });
        // this.reset();
        // this.open = true;
        // this.title = "添加盘点计划";
        // this.form.storeId = this.queryParams.storeId
        // this.form.deptId = this.queryParams.deptId
      },
      /** 修改按钮操作 */
      handleUpdate(row) {
        // this.loading = true;
        // this.reset();
        // const id = row.id || this.ids
        // getInventoryPlan(id).then(response => {
        //   this.loading = false;
        //   this.form = response.data;
        //   this.open = true;
        //   this.title = "修改盘点计划";
        // });
        const id = row.id || this.ids
        this.$router.push({
          path: '/wms/inventoryPlan/edit/' + id,
          query: {
            pageNum: this.queryParams.pageNum
          }
        });
      },
      handleInfo(row) {
        getInventoryPlan(row.id).then(response => {
          this.title = '盘点计划详情'
          this.open = true
          this.form = response.data;
          this.listItems = [];
          this.listItems.push(this.form.items);
          // if (this.form.items && this.form.items.length > 25) {
          //   let items = this.form.items;
          //   var length = items.length;
          //   for (var i = 0; i * 25 <= length; i++) {
          //     let tempItems = items.slice(i * 25, (i + 1) * 25);
          //     if (tempItems && tempItems.length > 0) {
          //       this.listItems.push(tempItems)
          //     }
          //   }
          // } else {
          //   this.listItems.push(this.form.items);
          // }
        }).finally(() => {
          // this.$nextTick(() => {
          //   console.info("headerDiv===>",this.$refs['headerDiv'].offsetHeight);
          // });
        });
      },
      /** 提交按钮 */
      submitForm() {
        this.$refs["form"].validate(valid => {
          if (valid) {
            this.buttonLoading = true;
            if (this.form.id != null) {
              updateInventoryPlan(this.form).then(response => {
                this.$modal.msgSuccess("修改成功");
                this.open = false;
                this.getList();
              }).finally(() => {
                this.buttonLoading = false;
              });
            } else {
              addInventoryPlan(this.form).then(response => {
                this.$modal.msgSuccess("新增成功");
                this.open = false;
                this.getList();
              }).finally(() => {
                this.buttonLoading = false;
              });
            }
          }
        });
      },
      /** 删除按钮操作 */
      handleDelete(row) {
        const ids = row.id || this.ids;
        this.$modal.confirm('是否确认删除盘点计划编号为"' + ids + '"的数据项？').then(() => {
          this.loading = true;
          return delInventoryPlan(ids);
        }).then(() => {
          this.loading = false;
          this.getList();
          this.$modal.msgSuccess("删除成功");
        }).finally(() => {
          this.loading = false;
        });
      },
      /** 导出按钮操作 */
      handleExport() {
        this.download('wms/inventoryPlan/export', {
          ...this.queryParams
        }, `inventoryPlan_${new Date().getTime()}.xlsx`)
      },

      exportPlanPro(){
        this.download('wms/inventoryPlan/exportPlanPro', {
          id: this.form.id
        }, `inventoryPlanPro_${new Date().getTime()}.xlsx`)
      },
      deletePlanPro(){
        let deleteParams = {
          inventoryNo: this.form.inventoryNo,
          proNos: this.deletePlanProList
        }
        removeDtl(deleteParams).then(response => {
          this.$modal.msgSuccess("删除成功");
          this.open = false;
          this.getList();
        }).finally(() => {
          this.buttonLoading = false;
        });
      },
      handleResults() {
        let ids = this.ids;
      },
      handlePrint(title) {
        // const printOrder = this.$refs['printOrder'];
        // htmlToPdf('#printOrderPre',title)
        this.$refs.easyPrint.print()
      },
      handlePrintInfo(title) {
        htmlToPdfInfo("#printOrderPre");
      },
    }
  };
</script>
<style lang="scss" scoped >
  @import './plan.scss';
</style>
